﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;

namespace NodeControl 
{
	/// <summary>
	/// Interaction logic for Node.xaml
	/// </summary>
	public partial class Node : UserControl
	{
        public Node(Ellipse e, double canWidth)
        {
            this.InitializeComponent();

            Position(e, canWidth);
        }

        public Node(DataRow dr, Ellipse e, double canWidth)
        {
            this.InitializeComponent();

            Position(e, canWidth);

            this.NodeMean = double.Parse(dr[6].ToString());
            this.NodeNumVect = int.Parse(dr[8].ToString());
            this.NodeVariance= double.Parse(dr[7].ToString());
            this.NodeAttrNum = int.Parse(dr[9].ToString());
            this.NodeAttrVal = double.Parse(dr[10].ToString());
            this.NodeQuality = double.Parse(dr[11].ToString());
        }

        void Position(Ellipse e, double canWidth)
        {
            double top = Canvas.GetTop(e);
            double left = Canvas.GetLeft(e);

            Canvas.SetTop(this, top - (this.Height / 2) + (e.Height / 2));

            if (left < (this.Width / 2) - (e.Width / 2))
            {
                Canvas.SetLeft(this, 0);
            }
            else if (left > canWidth - e.Width - (this.Width / 2))
            {
                Canvas.SetLeft(this, canWidth - this.Width);
            }
            else
            {
                Canvas.SetLeft(this, left - (this.Width / 2) + (e.Width / 2));
            }
        }

        public Color NodeColorIn
        {
            get { return this.ColorIn.Color; }
            set { this.ColorIn.Color = value; }
        }

        public Color NodeColorOut
        {
            get { return this.ColorOut.Color; }
            set { this.ColorOut.Color = value; }
        }

	    public double NodeMean
	    {
            get { return double.Parse(this.MeanVal.Text); }
            set { this.MeanVal.Text = Math.Round(value, 4).ToString(); }
	    }

        public int NodeNumVect
        {
            get { return int.Parse(this.NumVectVal.Text); }
            set { this.NumVectVal.Text = value.ToString(); }
        }

        public double NodeVariance
        {
            get { return double.Parse(this.VarianceVal.Text); }
            set { this.VarianceVal.Text = Math.Round(value, 4).ToString(); }
        }

        public int NodeAttrNum
        {
            get { return int.Parse(this.AttrNumVal.Text); }
            set { this.AttrNumVal.Text = value.ToString(); }
        }

        public double NodeAttrVal
        {
            get { return double.Parse(this.AttrValVal.Text); }
            set { this.AttrValVal.Text = Math.Round(value, 4).ToString(); }
        }

        public double NodeQuality
        {
            get { return double.Parse(this.QualityVal.Text); }
            set { this.QualityVal.Text = Math.Round(value, 4).ToString(); }
        }
	}
}